/**
 * @param {number[]} nums
 * @return {number}
 */
var removeDuplicates = function (nums) {
    let n = nums.length;
    if (n === 0) return 0;
    if (n === 1) return 1;
    let slow = 0, fast = 1;
    while (fast < n) {
        if (nums[fast] !== nums[slow]) {
            slow++;
            // 维护nums[0...slow]无重复
            nums[slow] = nums[fast];
        }
        fast++;
    }

    // 长度为索引+1
    return slow + 1;
};

var removeDuplicates = function (head) {
    if (head == null) return null;
    let slow = head, fast = head.next;
    while (fast != null) {
        if(fast.val !== slow.val){
            // nums[slow] = nums[fast];
            slow.next = fast;
            // slow++;
            slow = slow.next;
        }

        // fast++
        fast = fast.next;
    }

    // 断开与后面重复元素的连接
    slow.next = null;
    return head;
}